home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / os2 / vsoup11.zip / yarnio.cmd < prev   
OS/2 REXX Batch file  |  1996-09-04  |  10KB  |  366 lines

  1. /*
  2.  *  make IO for Yarn -  rg070596
  3.  *
  4.  *  rg130696:
  5.  *  - Umstieg auf vsoup (zuerst für News-Empfang)
  6.  *  - große Veränderung:
  7.  *    es können Mails/News versendet werden und gleichzeitig Mails und News
  8.  *    getrennt empfangen werden
  9.  *  rg180796:
  10.  *  - import versucht es solange bis soup.zip auch wirklich angenommen wurde
  11.  *    (wird nicht, wenn Yarn aktiv)
  12.  *  - SEND verpackt im erfolglosen Fall die Dateien einfach wieder.
  13.  *    Dann können sie in Yarn weiterhin bearbeitet werden.
  14.  *
  15.  *  environment vars:
  16.  *  - home
  17.  *  - tmp
  18.  *  - yarn
  19.  *
  20.  *  directory structure (must be set up manually!):
  21.  *  - %home%\yarn\in       - files for reception
  22.  *  - %home%\yarn\in\mail  - files for received mail
  23.  *  - %home%\yarn\in\news  - files for received news
  24.  *  - %home%\yarn\in\news2 - files for received news from alternative source
  25.  *  - %home%\yarn\out      - souper packets for transmission
  26.  *  - %yarn%\bin           - yarn executables and so on
  27.  *    (the news db is under %yarn%\news)
  28.  *
  29.  *  external utilities:
  30.  *  - %yarn%\bin\vsoup.exe  - soup packet receiver transmitter
  31.  *  - %yarn%\bin\import.exe
  32.  *
  33.  *  options: (actually none, all internally used)
  34.  *  - SEND      - start the send process
  35.  *  - RCVMAIL   - start the receive mail process
  36.  *  - RCVNEWS   - start the receive news process
  37.  *  - RCVNEWS2  - start the alternate receive news process
  38.  *  with no option given, YarnIo starts all the above processes
  39.  *
  40.  *  todo:
  41.  *  - restructure script, so that there are several procedures (& stems)
  42.  *  - handle more than one single news server (in a clean way)
  43.  *  - one semaphor for each process
  44.  */
  45.  
  46. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  47. call SysLoadFuncs
  48.  
  49. DEBUG = 0
  50.  
  51. /*
  52.  *  get some global vars
  53.  */
  54. env = 'os2environment'
  55. homeDir = value('home',,env)
  56. tmpDir  = value('tmp',,env)
  57. yarnDir = value('yarn',,env)
  58. parse source . . compCmdName
  59. cmdName = filespec('name',compCmdName)
  60. yarnBinDir = yarnDir || '\bin'
  61.  
  62. if (homeDir = '')  |  (tmpDir = '')  |  (yarnDir = '') then
  63.     call Help 'Either HOME or TMP or YARN not defined in environment'
  64.  
  65. /*
  66.  *  define some global vars (commands / directories)
  67.  *  change, if you like to
  68.  */
  69. xmtDir        = homeDir || '\yarn\out'
  70. xmtFileZip    = xmtDir  || '\reply.zip'         /* same as in yarn-config! */
  71. xmtFileMsg    = xmtDir  || '\????.msg'          /* mail/news.msg */
  72. rcvDir        = homeDir || '\yarn\in'
  73. rcvNewsDir    = rcvDir  || '\news'
  74. rcvNews2Dir   = rcvDir  || '\news2'
  75. rcvMailDir    = rcvDir  || '\mail'
  76.  
  77. clearNntp     = 'set nntpserver='
  78.  
  79. importProg    = yarnBinDir || '\import.exe'
  80. soupSend      = yarnBinDir || '\vsoup.exe -s'
  81. soupRcvNews   = yarnBinDir || '\vsoup.exe -m -a -t 5 -h' rcvNewsDir
  82. soupRcvNews2  = yarnBinDir || '\vsoup.exe -m -a -i -t 3 -h' rcvNews2Dir 'nntp://second.news.server'
  83. soupRcvMail   = yarnBinDir || '\vsoup.exe -n'
  84. soupRcvFile   = 'soup.zip'
  85. unzipProg     = 'unzip.exe -oq'
  86. zipProg       = 'zip -0mq' soupRcvFile 'areas *.msg'
  87. zipProgSend   = 'zip -mq' xmtFileZip 'replies ????.msg'
  88. rmSoupPacks   = 'rm -f areas *.msg *.idx'
  89.  
  90. /*
  91.  *  files for internal use
  92.  */
  93. semActive   = tmpdir  || '\yarnio.act'
  94. semImport   = tmpdir  || '\yarnio.imp'
  95. flgRcvNews  = tmpdir  || '\yarnio.frn'
  96. flgRcvNews2 = tmpDir  || '\yarnio.fr2'
  97. flgRcvMail  = tmpDir  || '\yarnio.frm'
  98. flgXmt      = tmpDir  || '\yarnio.fx'
  99.  
  100. if \DEBUG then do
  101.    startProc = 'start /c /b /min'
  102. end
  103. else do
  104.    startProc = 'start /c /b'
  105. end
  106.  
  107.  
  108. if DEBUG then trace('i')
  109.  
  110. /*
  111.  *  get command line options
  112.  */
  113. parse arg Option ropt
  114. if ropt \= '' then
  115.    call Help 'too many options (options are for internal use anyway...)'
  116.  
  117. /*
  118.  *  define cleanup routine
  119.  */
  120. /*  if signals are caught, then the handler is called, even if soup is aborted (I dont want this)
  121. signal on failure name CleanUp
  122. signal on halt    name CleanUp
  123. signal on error   name CleanUp
  124. */
  125.  
  126. /*
  127.  *  do the thing
  128.  */
  129. if Option = '' then do
  130.    /*
  131.     *  main process:  initiate all other processes and wait for completion
  132.     */
  133.    if stream(semActive,'c','open write') = 'READY:' then do
  134.       say 'starting the transmitting/receiving processes...'
  135.       rc = SysFileDelete( flgRcvNews )
  136.       rc = SysFileDelete( flgRcvNews2 )
  137.       rc = SysFileDelete( flgRcvMail )
  138.       rc = SysFileDelete( flgXmt )
  139.       '@' startProc '"YarnIo SEND"'     CompCmdName 'SEND'
  140.       '@' startProc '"YarnIo RCVMAIL"'  CompCmdName 'RCVMAIL'
  141.       '@' startProc '"YarnIo RCVNEWS"'  CompCmdName 'RCVNEWS'
  142.       '@' startProc '"YarnIo RCVNEWS2"' CompCmdName 'RCVNEWS2'
  143.       say 'waiting...'
  144.       loopCnt = 0
  145.       do forever
  146.          rc = SysSleep( 1 )
  147.          loopCnt = loopCnt + 1
  148.          if loopCnt > 3600 then do
  149.             say 'timeout:  cleaning up and exit...'
  150.             res = 3
  151.             leave
  152.          end
  153.          if FileExists(flgRcvNews) & FileExists(flgRcvMail) & FileExists(flgXmt) & FileExists(flgRcvNews2) then do
  154.             rc = SysSleep( 3 )
  155.             say ''
  156.             say 'results:'
  157.             say '--------'
  158.             say 'SEND:    ' linein( flgXmt )
  159.             say 'RCVMAIL: ' linein( flgRcvMail )
  160.             say 'RCVNEWS: ' linein( flgRcvNews )
  161.             say 'RCVNEWS2:' linein( flgRcvNews2 )
  162.             say ''
  163.             say 'finished...'
  164.             res = 0
  165.             leave
  166.          end
  167.       end
  168.       rc = lineout( flgXmt )
  169.       rc = lineout( flgRcvMail )
  170.       rc = lineout( flgRcvNews )
  171.       rc = lineout( flgRcvNews2 )
  172.       rc = SysFileDelete( flgRcvNews )
  173.       rc = SysFileDelete( flgRcvNews2 )
  174.       rc = SysFileDelete( flgRcvMail )
  175.       rc = SysFileDelete( flgXmt )
  176.       rc = stream(semActive,'c','close')
  177.       rc = SysFileDelete(semActive)
  178.       rc = SysSleep( 30 )
  179.       exit 0
  180.    end
  181.    else do
  182.       say CmdName 'already active'
  183.       say '(if actually not, delete' semActive 'manually)'
  184.       exit 3 
  185.    end
  186. end
  187. else if Option = 'SEND' then do
  188.    /*
  189.     *  transmit messages (news & mail):
  190.     *  First try to transmit old *.msg, after that unpack and transmit reply.zip 
  191.     */
  192.    text = 'nothing done'
  193.    doneAny = 0
  194.    if DEBUG then rc = SysSleep( 10 )
  195.    if UCompare(directory(xmtDir),XmtDir) = 0 then do
  196.       if FileExists(xmtFileZip) then do
  197.          say 'sending' xmtFileMsg '(' || xmtFileZip || ')'
  198.          '@' unzipProg xmtFileZip
  199.          rc = SysFileDelete( xmtFileZip )
  200.          '@' echo soupSend
  201.          '@' soupSend
  202.          if rc = 0 then
  203.             text = 'msg(s) transmitted'
  204.          else
  205.             text = soupSend 'returned with an error'
  206.          if FileExists(xmtFileMsg) then do
  207.             say 'moving' xmtFileMsg 'again into' xmtFileZip
  208.             '@' zipProgSend
  209.          end
  210.          '@' zipProg
  211.          rc = DoImport(xmtDir)
  212.       end
  213.       else
  214.          text = 'nothing done'
  215.    end
  216.    else
  217.       text = 'cannot change to' XmtDir
  218.    if DEBUG then rc = SysSleep( 10 )
  219.    rc = lineout( flgXmt,text )
  220.    rc = lineout( flgXmt )
  221. end
  222. else if Option = 'RCVMAIL' then do
  223.    /*
  224.     *  receive mails
  225.     */
  226.    text = 'ok'
  227.    if DEBUG then rc = SysSleep( 10 )
  228.    if UCompare(directory(rcvMailDir),rcvMailDir) = 0 then do
  229.       '@' rmSoupPacks
  230.       '@' echo soupRcvMail
  231.       '@' soupRcvMail
  232.       if rc \= 0 then
  233.          text = soupRcvMail 'returned with an error'
  234.       '@' zipProg
  235.       rc = DoImport( rcvMailDir )
  236.    end
  237.    else
  238.       text = 'cannot change to' rcvMailDir
  239.    if DEBUG then rc = SysSleep( 10 )
  240.    rc = lineout( flgRcvMail,text )
  241.    rc = lineout( flgRcvMail )
  242. end
  243. else if Option = 'RCVNEWS' then do
  244.    /*
  245.     *  receive news
  246.     */
  247.    text = 'ok'
  248.    if DEBUG then rc = SysSleep( 10 )
  249.    if UCompare(directory(rcvNewsDir),rcvNewsDir) = 0 then do
  250.       '@' rmSoupPacks
  251.       '@' clearNntp
  252.       '@' echo soupRcvNews
  253.       '@' soupRcvNews
  254.       if rc \= 0 then
  255.          text = soupRcvNews 'returned with an error'
  256.       '@' zipProg
  257.       rc = DoImport( rcvNewsDir )
  258.    end
  259.    else
  260.       text = 'cannot change to' rcvNewsDir
  261.    if DEBUG then rc = SysSleep( 10 )
  262.    rc = lineout( flgRcvNews,text )
  263.    rc = lineout( flgRcv